% sby 6/15改
% by clq
% 2021/6/12
function[i_R, profits_R, EYI, EYin, ProfitPart] = round_robin(j_all,N)
addpath functions;
global CURRENT EYI EYin ProfitPart I J
ProfitPart = zeros(3, N);
EYI = zeros(1, N);
EYin = zeros(1, N);

%j_all is the given order of patient types


S = zeros(I,J);
i_R = zeros(1,N);
%Step1:find the optimal slot for each patient
for i=1:N
    CURRENT=i;
    i_R(1, CURRENT) = mod(CURRENT-1,I)+1; 

%Step2:find the profit after each patient is assigned
    j = j_all(CURRENT);
    S(i_R(1,CURRENT),j) = S(i_R(1,CURRENT),j)+1;
       Q = findQ(S); 
       R = findR(Q);
       profits_R(CURRENT) = function_fQR(Q,R);
end
return




